<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button color="#FFD700" block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    <div class="boxone">
      <div></div>
      <div @click="fnn">去注册</div>
    </div>
  </div>
</template>

<script>
import { login } from "../api/user";
import { SetToken } from "../utils/storeage";

export default {
  data() {
    return {
      username: "",
      password: "",
      registerlist: [],
    };
  },
  methods: {
    fnn() {
      this.$router.push("/resgiter");
    },
    async onSubmit() {
      const data = await login({
        username: this.username,
        password: this.password,
      });
      this.$toast.success("登录成功");
      SetToken(data.token);

      this.$router.push("/layout/mian");
    },
  },
};
</script>

<style>
.boxone {
  display: flex;
  justify-content: space-between;
}
</style>
